package 牛客题霸;

import java.util.ArrayList;
import java.util.List;

public class 链表的奇偶重排 {

    public ListNode oddEvenList(ListNode head) {
        if(head == null) {
            return null;
        }
        int count = 1;
        List<ListNode> ji = new ArrayList<>();
        List<ListNode> osu = new ArrayList<>();
        while (head != null) {
            if(count % 2 != 0) {
                ji.add(head);
            } else {
                osu.add(head);
            }
            count++;
            head = head.next;
        }
        ListNode dum = new ListNode(-1);
        ListNode cur = dum;
        for(ListNode node : ji) {
            cur.next = node;
            cur = cur.next;
        }
        for(ListNode node : osu) {
            cur.next = node;
            cur = cur.next;
        }
        cur.next = null;
        return dum.next;
    }

    public static void main(String[] args) {

    }

    public class ListNode {
        int val;
        ListNode next = null;

        public ListNode(int val) {
            this.val = val;
        }
    }
}
